const express = require('express');
const app = express();
// 告诉express 我们使用的模板的后缀是html
app.engine('html', require('express-art-template'));
// set template path 
app.set('views', './views');
let students = [
    {
        name: '张三',
        age: '18',
        sex: "男",
        hobby: '篮球'
    }, {
        name: '张三1',
        age: '18',
        sex: "男",
        hobby: '养马'
    }, {
        name: '张三2',
        age: '18',
        sex: "男",
        hobby: '汤头'
    }, {
        name: '张三3',
        age: '18',
        sex: "男",
        hobby: '抽烟'
    }, {
        name: '张三4',
        age: '19',
        sex: "女",
        hobby: '篮球'
    }
];
app.get('/', (req, res) => {
    // 响应 渲染的模板，students.html会去view目录下找
    res.render('students.html', { students: students });
})
// start server
app.listen(80, () => {
    console.log('start server');
})

// express中config template engine
// 1.download: 
// npm install --save art-template
// npm install --save express-art-template
// 2. config template postfix
// app.engine('html', require('express-art-template'))；
// 3. config template path
// app.set('views', './views') first views is template 
// 4. template and data join bind
// res.render('students.html', { students: students });
// res.render('template name', 'data Object');
